import 'package:flutter/material.dart';

class GradientButton extends StatelessWidget {
  const GradientButton({
    super.key,
    this.colors,
    this.height,
    this.width,
    this.borderRadius,
    this.onPressed,
    required this.child,
  });

  final Widget child;
  final List<Color>? colors;
  final double? height;
  final double? width;
  final BorderRadius? borderRadius;
  final Function()? onPressed;

  @override
  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
    List<Color> _colors =
        colors ?? [theme.primaryColor, theme.primaryColorDark];
    return DecoratedBox(
      decoration: BoxDecoration(
        gradient: LinearGradient(colors: _colors),
        borderRadius: borderRadius,
      ),
      child: Material(
        type: MaterialType.transparency,
        child: ConstrainedBox(
          constraints: BoxConstraints.tightFor(width: width, height: height),
          child: InkWell(
            onTap: onPressed,
            child: Padding(
              padding: EdgeInsets.all(10),
              child: DefaultTextStyle(
                style: TextStyle(fontWeight: FontWeight.bold),
                child: child,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
